Spatial Data Visualization

In this chapter, we discuss spatial data visualization techniques. Spatial data contains measurements of various geographical locations, areas, path, and etc. Therefore, its visualizations are often based on maps. In this chapter, we will go over a few typical map visualizations. To generate these visualizations, we need the following R packages.

library(tidyverse)
library(ggmap) # devtools::install_github("dkahle/ggmap")
library(RColorBrewer)
library(statebins)
library(viridis)
library(viridisLite)
library(geofacet) # takes long time to install.
library(geosphere)
library(grid)
library(gridExtra)
#For windows OS, you may need to install Rtools from: https://cran.r-project.org/bin/windows/Rtools/rtools40.html

1 Instructions on Setting Google Cloud Platform to Use ggmap

In order to use ggmap to generate map visualizaiton, we need to set up the Google Cloud Platform properly. We explain the setup of the Google Cloud Platform in

library(ggmap)
ggmap::register_google(key = "AIzaSyDg3Lt5Mof5kGMv5cFet6qGLE5SNG6yvs4")
geocode('Univerisity of Cincinnati',output = 'more')
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Univerisity+of+Cincinnati&key=xxx
## # A tibble: 1 x 9
##     lon   lat type          loctype address              north south  east  west
##   <dbl> <dbl> <chr>         <chr>   <chr>                <dbl> <dbl> <dbl> <dbl>
## 1 -84.5  39.1 establishment rooftop 2600 clifton ave, c~  39.1  39.1 -84.5 -84.5
UClayer_goo_ter <- get_map(location = "University of Cincinnati", zoom = 15, 
                           source = "google", maptype = "terrain")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=University%20of%20Cincinnati&zoom=15&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=University+of+Cincinnati&key=xxx
ggmap(UClayer_goo_ter,extent = 'device') + ggtitle("Google Maps Terrain")